﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XinYi.CrookedShow.Models;
using XinYi.CrookedShowMode;
using XinYi.CrookedTopShow.BLL;

namespace XinYi.CrookedShow.Controllers
{
    public class UserInfoController : Controller
    {
        #region 前台登录是否存在
        public JsonResult UserInfoIsNotExist(UserInfo user, bool check)
        {
            Operate operate = new Operate();
            UserInfoService userService = new UserInfoService();
            UserInfo userInfo = userService.UserInfoIsNotExist(user);
            if (userInfo != null)
            {
                //存储session值
                UserInfoContext.adminContext.adminInfo = userInfo;
                //如果选中保存密码则存储cookie
                if (check)
                {
                    //存储cookie
                    //创建一个Cookie对象
                    HttpCookie httpCookie = new HttpCookie("CookieName");
                    //设置Cookie的值
                    httpCookie.Values.Add("Name", userInfo.UserName);
                    httpCookie.Values.Add("Password", userInfo.Pwd);
                    httpCookie.Values.Add("DateTime", DateTime.Now.AddDays(7).ToString("yyyy-MM-dd HH:mm:ss"));
                    //设置Cookie的过期时间
                    httpCookie.Expires = DateTime.Now.AddDays(7);
                    System.Web.HttpContext.Current.Response.Cookies.Add(httpCookie);
                }
            }
            operate.Success = userInfo != null ? true : false;
            return Json(operate);
        }
        #endregion
    }
}